<?php
App::import('Vendor','xtcpdf'); 

$tcpdf = new XTCPDF();
$textfont = 'freesans'; // looks better, finer, and more condensed than 'dejavusans'


// set document information
$tcpdf->SetCreator(PDF_CREATOR);
$author = $vorname." ".$name;
$tcpdf->SetAuthor($author);
$projectname = $pname." - Mass Swap";
$tcpdf->SetTitle($projectname);
$tcpdf->SetSubject('Management Report');

// set page properties
$tcpdf->SetAutoPageBreak(false);
$tcpdf->SetPageOrientation('L');
$tcpdf->setPrintHeader(true);
$tcpdf->setPrintFooter(false);

// set header details
$projectname = $pname." - Mass Swap";
$tcpdf->xheadertext = $projectname;
$tcpdf->xheadercolor = array(110, 183, 228);

// add a page
$tcpdf->AddPage();

// page content
$tcpdf->SetTextColor(146, 139, 129);
$tcpdf->SetFontSize(28);
$tcpdf->Text(30,36,'Management Report');

$maundabt = $vorname." ".$name.", Order Monitoring";
$datumandort = date("d.m.Y").", Otelfingen";

$tcpdf->SetFontSize(16);
$tcpdf->Text(30,60,$maundabt);
$tcpdf->Text(30,67,$datumandort);
$tcpdf->Text(30,90,"Project description: ".$pdescription);
$tcpdf->Image(IMAGES . 'upc-cablecom.jpg', 250, 165, 45, 45, 'JPG');

// page end
$tcpdf->endPage();

// set page properties
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(true);

// add a page
$tcpdf->AddPage();

// set table properties
$tcpdf->setCellPaddings(1, 1, 1, 1);
$tcpdf->SetFillColor(110, 183, 228);
$tcpdf->SetFontSize(11);

$titel1 = "Startdate";
$titel2 = "Status";
$titel3 = "Current Step";
$titel4 = "Total";
$titel5 = "Open";
$titel6 = "Skipped";
$titel7 = "Completed";

$tcpdf->SetTextColor(255, 255, 255,'',false);
$tcpdf->SetFillColor(168, 212, 239);
$tcpdf->SetFont('helvetica', 'B');
$tcpdf->MultiCell(20,  5, ''               , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel1          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel2          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(100, 5, $titel3          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel4          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel5          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel6          , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $titel7          , 1, 'L', 1, 1, '', '', true);
$tcpdf->SetTextColor(0, 0, 0,'',false);
$tcpdf->SetFont('helvetica');

$i = 0; $total1 = 0; $total2 = 0; $total3 = 0; $total4 = 0;
WHILE($row = mysql_fetch_array($result))
  {
	if($i == 21) {
		$tcpdf->SetTextColor(146, 139, 129,'',false);
		$tcpdf->SetFontSize(14);
		$snapshot = "Data snapshot: ".date("d.m.Y H:i");
		$tcpdf->Text(10,176,$snapshot);
		$tcpdf->Text(10,183,'A legend about steps and figures can be found on the last page');
		// page end
		$tcpdf->endPage();
		// set page properties
		$tcpdf->setPrintHeader(false);
		$tcpdf->setPrintFooter(true);
		// add a page
		$tcpdf->AddPage();
		// set table properties
		$tcpdf->setCellPaddings(1, 1, 1, 1);
		$tcpdf->SetFillColor(110, 183, 228);
		$tcpdf->SetFontSize(11);

		$titel1 = "Startdate";
		$titel2 = "Status";
		$titel3 = "Current Step";
		$titel4 = "Total";
		$titel5 = "Open";
		$titel6 = "Skipped";
		$titel7 = "Completed";

		$tcpdf->SetTextColor(255, 255, 255,'',false);
		$tcpdf->SetFillColor(168, 212, 239);
		$tcpdf->SetFont('helvetica', 'B');
		$tcpdf->MultiCell(20,  5, ''               , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel1          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel2          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(100, 5, $titel3          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel4          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel5          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel6          , 1, 'L', 1, 0, '', '', true);
		$tcpdf->MultiCell(25,  5, $titel7          , 1, 'L', 1, 1, '', '', true);
		$tcpdf->SetTextColor(0, 0, 0,'',false);
		$tcpdf->SetFont('helvetica');
		$i = 0;
	}
	
	if ($i++ % 2 == 0) { $tcpdf->SetFillColor(232, 231, 237); } else { $tcpdf->SetFillColor(226, 241, 250); }

	$batchname = "Batch ".$row["rid"];
	$startdate = $batch->startdatum($row["rid"]);
	$batchstatus = $batch->batchstatus($row["rid"]);
	$batchcurrentstep = $batch->currentstatus($row["order"]);
	$total = $batch->total($row["rid"]); $total1 = $total1 + $batch->total($row["rid"]);
	$open = $batch->open($row["rid"]); $total2 = $total2 + $batch->open($row["rid"]);
	$skipped = $batch->skipped($row["rid"]); $total3 = $total3 + $batch->skipped($row["rid"]);
	$completed = $batch->completed($row["rid"]); $total4 = $total4 + $batch->completed($row["rid"]);
	
	$tcpdf->MultiCell(20,  5, $batchname         , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $startdate         , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $batchstatus       , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(100, 5, $batchcurrentstep  , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $total             , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $open              , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $skipped           , 1, 'L', 1, 0, '', '', true);
	$tcpdf->MultiCell(25,  5, $completed         , 1, 'L', 1, 1, '', '', true);
  }
if ($i++ % 2 == 0) { $tcpdf->SetFillColor(232, 231, 237); } else { $tcpdf->SetFillColor(226, 241, 250); }

$prozopen = round((100/$total1*$total2),0); $popen = $total2." (".$prozopen."%)";
$prozskipped = round((100/$total1*$total3),0); $pskipped = $total3." (".$prozskipped."%)";
$pozcompleted = round((100/$total1*$total4),0); $pcompleted = $total4." (".$pozcompleted."%)";

$tcpdf->SetFont('helvetica', 'B');
$tcpdf->MultiCell(20,  5, 'TOTAL'   , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, ''        , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, ''        , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(100, 5, ''        , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $total1   , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $popen   , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $pskipped   , 1, 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(25,  5, $pcompleted  , 1, 'L', 1, 1, '', '', true);
$tcpdf->SetFont('helvetica');

$tcpdf->SetTextColor(146, 139, 129,'',false);
$tcpdf->SetFontSize(14);
$snapshot = "Data snapshot: ".date("d.m.Y H:i");
$tcpdf->Text(10,176,$snapshot);
$tcpdf->Text(10,183,'A legend about steps and figures can be found on the last page');



// page end
$tcpdf->endPage();
// set page properties
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(true);
// add a page
$tcpdf->AddPage();

$tcpdf->SetFont('helvetica', 'B');
$tcpdf->SetFontSize(14);
$tcpdf->setCellPaddings(1, 1, 1, 1);
$tcpdf->SetTopMargin(15);
$tcpdf->SetLeftMargin(30);
$tcpdf->MultiCell(80,  5, 'Legend Figures'   , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, ''   , 0, 'L', 0, 1, '', '', true);
$tcpdf->SetFont('helvetica');
$tcpdf->SetFontSize(10);

$text1 = "Total MACs in the batch.";
$text2 = "MACs which having a ongoing swap order in Clarify.";
$text3 = "MACs where the CPE was already swapped or the service churned in the meantime.";
$text4 = "MACs where the CPE was successfully swapped and replaced.";


$tcpdf->MultiCell(80,  5, 'Total'     , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $text1      , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, 'Open'      , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $text2      , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, 'Skipped'   , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $text3      , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, 'Completed' , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $text4      , 0, 'L', 0, 1, '', '', true);

$tcpdf->MultiCell(80,  5, '' , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, '' , 0, 'L', 0, 1, '', '', true);



$tcpdf->SetFont('helvetica', 'B');
$tcpdf->SetFontSize(14);
$tcpdf->setCellPaddings(1, 1, 1, 1);
$tcpdf->MultiCell(100,  5, 'Legend Steps'   , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, ''   , 0, 'L', 0, 1, '', '', true);
$tcpdf->SetFont('helvetica');
$tcpdf->SetFontSize(10);

$textlst1  = "Waiting for MAC details";
$textlst2  = "Waiting for detail data from clarify";
$textlst3  = "Waiting for file comparison";
$textlst4  = "Waiting for data breakdown";
$textlst5  = "Waiting for address corrections";
$textlst6  = "Waiting for Intrum export details";
$textlst7  = "Waiting for Intrum import details";
$textlst8  = "Waiting for Schmied Fehr export";
$textlst9  = "Waiting for CTSP file export";
$textlst10 = "Waiting for interaction file export";
$textlst11 = "Waiting for letter delivery by Schmid Fehr";
$textlst12 = "Waiting for final MAC export";
$textlst13 = "Waiting for mass swap run";
$textlst14 = "Waiting for weborder details";
$textlst15 = "Waiting for clarify data details";
$textlst16 = "Swap orders ongoing";

$textlsd1  = "MACs for batch have to be specified.";
$textlsd2  = "Detail data for MACs from Clarify have to be uploaded";
$textlsd3  = "MAC list and Clarify details will be compared to find missing MACs.";
$textlsd4  = "Some MACs have to be excluded from mass swap and have to be processed manually.";
$textlsd5  = "Address for letter delivery has to be corrected.";
$textlsd6  = "Customer data has to be exported for Intrum credit check.";
$textlsd7  = "Customer data with Intrum credit check details has to be imported.";
$textlsd8  = "Data for Schmid Fehr letters has to be exported.";
$textlsd9  = "Data for CTSP Modem hints has to be exported.";
$textlsd10 = "Data for Clarify Interactions has to be exported.";
$textlsd11 = "Waiting 72h until Schmid Fehr has delivery all letters.";
$textlsd12 = "Final MAC list has to be exported for mass swap run.";
$textlsd13 = "Waiting for a mass swap run. Runs are executed between 19:00 and 22:00 and only one batch per day.";
$textlsd14 = "Weborder details from the mass swap run has to be imported.";
$textlsd15 = "Weborders will be updated with Clarify part request data.";
$textlsd16 = "Swap orders are ongoing in Clarify.";

$tcpdf->MultiCell(80,  5, $textlst1  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd1  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst2  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd2  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst3  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd3  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst4  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd4  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst5  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd5  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst6  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd6  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst7  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd7  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst8  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd8  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst9  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd9  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst10  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd10  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst11  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd11  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst12  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd12  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst13  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd13  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst14  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd14  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst15  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd15  , 0, 'L', 0, 1, '', '', true);
$tcpdf->MultiCell(80,  5, $textlst16  , 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(200, 5, $textlsd16  , 0, 'L', 0, 1, '', '', true);


$projectname2 = $pname."-Management-Report.pdf";
echo $tcpdf->Output($projectname2, 'D');

?>